<?php
if (preg_match("/\\d+\\.\\d+\\.\\d+\\.\\d+/", $_SERVER['HTTP_HOST']))
{
    header("HTTP/1.0 404 Not Found");
    exit();
}
error_reporting(0);
$g_conf = array();
include_once( "hip.php" );
include_once( "config.php" );
include_once( "class/functions.php" );
include_once( "class/db.php" );
include_once( "class/sessions.php" );
include_once( "class/user.php" );
include_once( "class/template.php" );
include_once( "class/ui.php" );
include_once( "class/config.php" );
include_once( "function.php" );
if (!isset($_SESSION['uid']))
{
    echo "-3,SYSTEM ERROR! (CODE: -3)";
    exit();
}
$rs = getdb("select id,open from lotto where open>='" . date("Y-m-d") . "' order by open");
if ($rs->eof)
{
    echo "-4,SYSTEM ERROR! (CODE: -4)";
    exit();
}
$lotto_id = $rs->f['id'];
$open = $rs->f['open'];
$rs->close();
$conf = new Config();
$stopbet = $conf->get("stopbet");
if (date("Y-m-d") < $open)
{
    echo "-5,SYSTEM ERROR! (CODE: -5)";
    exit();
}
else if (date("Y-m-d") == $open)
{
    if ($stopbet <= date("Hi"))
    {
        echo "-6,SYSTEM ERROR! (CODE: -6)";
        exit();
    }
    else if (date("Hi") <= $conf->get("startbet"))
    {
        echo "-5,SYSTEM ERROR! (CODE: -5)";
        exit();
    }
}
$curruser = User::getuser();
$disk = getUserValidDisk($curruser);
$userid = $curruser['id'];
$user_rate0 = get_share_rate0($userid);
$user_rate8 = $user_rate0 * get_share_rate0_8($userid);
$disk_name = array("", "a", "b", "c", "d");
if ($lotto_id == 0)
{
    echo "-1,ID ERROR! (CODE: -1)";
    exit();
}
$p = explode("-", $_GET['b']);
$b = $p[0];
$order = $p[1];
switch ($b)
{
    case "0" : //特碼A畫面
        $rs = getdb("select * from rate0" . $disk_name[$disk] . " where lotto_id=" . $lotto_id);
        if ($rs->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        $rss = get_srates_data($userid, $lotto_id, 0);
        if ($rss->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        $rs1 = getdb("select * from rate1" . $disk_name[$disk] . " where lotto_id=" . $lotto_id);
        if ($rs1->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        $rss1 = get_srates_data($userid, $lotto_id, 1);
        if ($rss1->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        echo "0";
        $i = 1;
        while ($i < 50)
        {
            echo "," . trimfloat($rs->f["r" . d2($i)] - $rss->f["r" . d2($i)] - $user_rate0, 1);
            ++$i;
        }
        echo "," . trimfloat($rs1->f['r1_1'] - $rss1->f['r1_1'] - $user_rate8, 1) . "," . trimfloat($rs1->f['r1_2'] - $rss1->f['r1_2'] - $user_rate8, 1);//特单
        echo "," . trimfloat($rs1->f['r2_1'] - $rss1->f['r2_1'] - $user_rate8, 1) . "," . trimfloat($rs1->f['r2_2'] - $rss1->f['r2_2'] - $user_rate8, 1);//特大
        echo "," . trimfloat($rs1->f['r3_1'] - $rss1->f['r3_1'] - $user_rate8, 1) . "," . trimfloat($rs1->f['r3_2'] - $rss1->f['r3_2'] - $user_rate8, 1);//合单
        echo "," . trimfloat($rs1->f['r13_1'] - $rss1->f['r13_1'], 1) . "," . trimfloat($rs1->f['r13_2'] - $rss1->f['r13_2'], 1) . "," . trimfloat($rs1->f['r13_3'] - $rss1->f['r13_3'], 1);//波色
        echo "," . trimfloat($rs1->f['r20_1'] - $rss1->f['r20_1'] - $user_rate8, 1) . "," . trimfloat($rs1->f['r20_2'] - $rss1->f['r20_2'] - $user_rate8, 1);//家禽
        echo "," . trimfloat($rs1->f['r28_1'] - $rss1->f['r28_1'] - $user_rate8, 1) . "," . trimfloat($rs1->f['r28_2'] - $rss1->f['r28_2'] - $user_rate8, 1);//尾大
        echo "," . trimfloat($rs1->f['r47_1'] - $rss1->f['r47_1'] - $user_rate8, 1) . "," . trimfloat($rs1->f['r47_2'] - $rss1->f['r47_2'] - $user_rate8, 1);//合大
        break;
    case "1" : //雙面盤
        $rs1 = getdb("select * from rate1" . $disk_name[$disk] . " where lotto_id=" . $lotto_id);
        if ($rs1->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        $rss1 = get_srates_data($userid, $lotto_id, 1);
        if ($rss1->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
		$rs2 = getdb("select * from rate5" . $disk_name[$disk] . " where lotto_id=" . $lotto_id);
        if ($rs1->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        $rss2 = get_srates_data($userid, $lotto_id, 5);
        if ($rss1->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
		//
		$zm = getdb("select * from rate15" . $disk_name[$disk] . " where lotto_id=" . $lotto_id);
        if ($zm->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        $zms = get_srates_data($userid, $lotto_id, 23);
        if ($zms->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        echo "1";
        echo "," . trimfloat($rs1->f['r1_1'] - $rss1->f['r1_1'] - $user_rate8, 1) . "," . trimfloat($rs1->f['r1_2'] - $rss1->f['r1_2'] - $user_rate8, 1);//特单
        echo "," . trimfloat($rs1->f['r2_1'] - $rss1->f['r2_1'] - $user_rate8, 1) . "," . trimfloat($rs1->f['r2_2'] - $rss1->f['r2_2'] - $user_rate8, 1);//特大
        echo "," . trimfloat($rs1->f['r3_1'] - $rss1->f['r3_1'] - $user_rate8, 1) . "," . trimfloat($rs1->f['r3_2'] - $rss1->f['r3_2'] - $user_rate8, 1);//合单
		echo "," . trimfloat($rs1->f['r47_1'] - $rss1->f['r47_1'] - $user_rate8, 1) . "," . trimfloat($rs1->f['r47_2'] - $rss1->f['r47_2'] - $user_rate8, 1);//合大
        echo "," . trimfloat($rs2->f['r5_1'] - $rss2->f['r5_1'], 1) . "," . trimfloat($rs2->f['r5_2'] - $rss2->f['r5_2'], 1); //总单
        echo "," . trimfloat($rs2->f['r6_1'] - $rss2->f['r6_1'], 1) . "," . trimfloat($rs2->f['r6_2'] - $rss2->f['r6_2'], 1); //总大
		//正码1-6
		$i = 1;
        while ($i <= 6)
        {
            $j = 1;
            while ($j <= 9)
            {
				if(!($j>=5 && $j<=7))
                	echo "," . trimfloat($zm->f["r15_" . $i . "_" . $j] - $zms->f["r15_" . $i . "_" . $j], 1);
                ++$j;
            }
            ++$i;
        }
		break;
    case "2" : //正码特 A
		$rs = getdb("select * from rate4" . $order . $disk_name[$disk] . " where lotto_id=" . $lotto_id);
        if ($rs->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        $rss = get_srates_data($userid, $lotto_id, 25, $order);
        if ($rss->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        echo "2";
        $i = 1;
        while ($i < 50)
        {
            echo "," . trimfloat($rs->f["r" . d2($i)] - $rss->f["r" . d2($i)], 1);
            ++$i;
        }
		break;
	case "3" ://正码特B
		break;
	case "4"://正码A
		$rs = getdb("select * from rate4" . $disk_name[$disk] . " where lotto_id=" . $lotto_id);
        if ($rs->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        $rss = get_srates_data($userid, $lotto_id, 4);
        if ($rss->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
		$rs2 = getdb("select * from rate5" . $disk_name[$disk] . " where lotto_id=" . $lotto_id);
		if ($rs2->eof)
		{
			echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
			exit();
		}
		$rss2 = get_srates_data($userid, $lotto_id, 5);
		if ($rss2->eof)
		{
			echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
			exit();
		}
        echo "4";
        $i = 1;
        while ($i < 50)
        {
            echo "," . trimfloat($rs->f["r" . d2($i)] - $rss->f["r" . d2($i)], 1);
            ++$i;
        }
        echo "," . trimfloat($rs2->f['r5_1'] - $rss2->f['r5_1'], 1) . "," . trimfloat($rs2->f['r5_2'] - $rss2->f['r5_2'], 1);
        echo "," . trimfloat($rs2->f['r6_1'] - $rss2->f['r6_1'], 1) . "," . trimfloat($rs2->f['r6_2'] - $rss2->f['r6_2'], 1);
		break;
    case "5" ://正码B
        break;
	case "6": //正码1~6
        $rs = getdb("select * from rate15" . $disk_name[$disk] . " where lotto_id=" . $lotto_id);
        if ($rs->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        $rss = get_srates_data($userid, $lotto_id, 23);
        if ($rss->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        echo "6";
        $i = 1;
        while ($i <= 6)
        {
            $j = 1;
            while ($j <= 9)
            {
                echo "," . trimfloat($rs->f["r15_" . $i . "_" . $j] - $rss->f["r15_" . $i . "_" . $j], 1);
                ++$j;
            }
            ++$i;
        }
        break;
	case "7" ://半波
        $rs = getdb("select * from rate1" . $disk_name[$disk] . " where lotto_id=" . $lotto_id);
        if ($rs->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        $rss1 = get_srates_data($userid, $lotto_id, 1);
        if ($rss1->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        echo "7";
        $i = 1;
        while ($i <= 12)
        {
            echo "," . trimfloat($rs->f["r18_" . $i] - $rss1->f["r18_" . $i], 1);
            ++$i;
        }
        break;
	case "8" ://一肖&正特尾
        $rs1 = getdb("select * from rate1" . $disk_name[$disk] . " where lotto_id=" . $lotto_id);
        if ($rs1->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        $rss1 = get_srates_data($userid, $lotto_id, 1);
        if ($rss1->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        echo "8";
        $i = 1;
        while ($i <= 12)
        {
			echo "," . trimfloat($rs1->f["r21_" . $i] - $rss1->f["r21_" . $i] - 0, 1);
            ++$i;
        }
        $i = 1;
        while ($i <= 10)
        {
            echo "," . trimfloat($rs1->f["r22_" . $i] - $rss1->f["r22_" . $i] - 0, 1);
            ++$i;
        }
		break;
    case "9" ://特肖头尾
        $rs = getdb("select * from rate1" . $disk_name[$disk] . " where lotto_id=" . $lotto_id);
        if ($rs->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        $rss = get_srates_data($userid, $lotto_id, 1);
        if ($rss->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
		$rs2 = getdb("select * from rate37 where lotto_id=" . $lotto_id." and bettype=49 and disk=".$disk);
        if ($rs2->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
		$rs3 = getdb("select * from rate37 where lotto_id=" . $lotto_id." and bettype=50 and disk=".$disk);
        if ($rs3->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        echo "9";
        $i = 1;
        while ($i <= 12)
        {
            echo "," . trimfloat($rs->f["r14_" . $i] - $rss->f["r14_" . $i], 1);
            ++$i;
        }
		$i = 0;
        while ($i <= 4)
        {
            echo "," . trimfloat($rs2->f["r" . $i], 1);
            ++$i;
        }
		$i = 0;
        while ($i <= 9)
        {
            echo "," . trimfloat($rs3->f["r" . $i], 1);
            ++$i;
        }
        break;
    case "10"://不中
		$rs = getdb("Select * from rate29 where lotto_id={$lotto_id} and bettype={$order} and disk={$disk}");
        if ($rs->eof)
        {
            echo "-2,DATABASE OPEN ERROR! (CODE: -2)";
            exit();
        }
        echo "10";
        $i = 1;
        while ($i < 50)
        {
            echo "," . trimfloat($rs->f["r" . d2($i)], 1);
            ++$i;
        }
		break;
}